package com.you.modules.user.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.google.common.base.Preconditions;
import com.you.modules.user.dao.IUserInfoDao;
import com.you.modules.user.mapper.UserInfoMapper;
import com.you.modules.user.model.UserInfo;
import com.you.modules.user.service.IUserInfoService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 *<p>
 *用户表 服务类
 *</p>
 *
 * @author : liu.yang.
 * @date : 2018-07-08 星期日 18:09:48
 * @since : 1.0.0
 */
@Service("userInfoService")
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements IUserInfoService {

    @Autowired
    private IUserInfoDao userInfoDao;
    @Override
    public UserInfo get(Integer id) {
        UserInfo user = null;
        if(null==id){
            return user;
        }
        return userInfoDao.get(id);
    }

    @Override
    public UserInfo save(UserInfo userInfo) {
        if(null==userInfo){
            Preconditions.checkNotNull(userInfo, "userInfo is null");
        }
        return userInfoDao.save(userInfo);
    }

    @Override
    public List<UserInfo> findAll() {
        return userInfoDao.findAll();
    }

    @Override
    public List<UserInfo> findByUsername(String username) {
        if(StringUtils.isEmpty(username)){
            return new ArrayList<UserInfo>();
        }
        return userInfoDao.findByUsername(username);
    }
}
